<template>
  <div class="content-box">
    <nav-title title="家庭情况" />
    <div class="line">
      <span class="important">*</span>
      <div class="label">姓名</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="fams.cName">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">性别</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="sexList" v-model="fams.cFamilySex"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">关系</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="relationShipList" v-model="fams.cRelationFam"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">工作单位</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="fams.cCompany">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">职务</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="fams.cPosition">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">联系电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="fams.cPhone">
      </div>
    </div>
    <div class="submit-btn" @click="save">
      保存
    </div>
    <div class="remove-btn" @click="remove">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { saveFamily,delFamily,getDicItem } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getDic();
  },
  created() {
    this.getFams()
    if(this.$store.state.hid){
      this.fams.rsHireId = this.$store.state.hid
      this.famsDel.rsHireId = this.$store.state.hid
    }
  },
  methods: {
    getDic(){
      //性别字典
      getDicItem({fileName: 'SEX'}).then(res=>{
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.sexList.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
          }
        }
      }).catch(res=>{

      });
      //关系字典
      getDicItem({fileName: 'C_RELATION_FAM'}).then(res=>{
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.relationShipList.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
          }
        }
        
      }).catch(res=>{

      })

    },
    save(){
      const that = this
      if(that.fams.cName == undefined || that.fams.cName == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入姓名'
        });
        return;
      }
      if(that.fams.cFamilySex == undefined || that.fams.cFamilySex == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择性别'
        });
        return;
      }
      if(that.fams.cRelationFam == undefined || that.fams.cRelationFam == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入关系'
        });
        return;
      }

      saveFamily(json2Form(that.fams)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })
    },
    remove(){

      const that = this;
      that.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delFamily(json2Form(that.fams)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                that.$vux.alert.show({
                  title: '提示',
                  content: '删除成功',
                  onHide () {
                    that.$router.push('/informationCollection/userInfo');
                  }
                })
              }else{
                // 显示
                that.$vux.alert.show({
                  title: '',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              that.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })

            
          }
        })

    },
    getFams() {
      if(this.$route.params.fam){
        this.fams = this.$route.params.fam
        this.famsDel = this.$route.params.fam.cSeqno
        console.log(this.fams)
      }
    }

  },
  data() {
    return {
      fams:{
        rsHireId: '',
      },
      famsDel: {
        rsHireId: '',
        cSeqno:''
      },
      sexList: [],
      relationShipList: [],
    }
  }
}

</script>
<style type="text/scss" lang="scss" scoped>
@import "./editinfo";
</style>
